﻿using Abp.Dependency;
using Batman.Cms.Core.Commands;
using Batman.Cms.Core.Core.Configurations;
using Batman.Cms.Core.Razor;
using Batman.Cms.Core.Tools;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;

namespace Batman.Cms.Core
{
    public static class Startup
    {
        public static void AddBatmanCore(this IServiceCollection services)
        {
            services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<RazorViewEngineOptions>, PluginRazorViewEngineOptionsSetup>());

            services.AddTransient<UpYunConfigurations>();
            IocManager.Instance.Register<ToolBox, ToolBox>(DependencyLifeStyle.Singleton);
            IocManager.Instance.Register<UpYunTool, UpYunTool>(DependencyLifeStyle.Singleton);

            services.AddCommandPoolService(options => { });
        }

        public static void UseBatmanCore(this IApplicationBuilder app)
        {
            app.UseMiddleware<PluginStaticFileMiddleware>();
        }
    }
}
